package org.oexam.ostudy.serv;

import java.io.IOException;
import java.sql.SQLException;

import javax.naming.NamingException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.oexam.ostudy.facade.ManageTestsPages;
import org.oexam.ostudy.facade.struct.TestDisplayDetails;
import org.oexam.ostudy.struct.AllResults;

/**
 * Servlet implementation class FinishTest
 */
@WebServlet("/FinishTest")
public class FinishTest extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#HttpServlet()
	 */
	public FinishTest() {
		super();
		// TODO Auto-generated constructor stub
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {

		ManageTestsPages manageTestsPages = new ManageTestsPages();

		TestDisplayDetails testData = (TestDisplayDetails) request.getSession()
				.getAttribute("testData");

		String res = "Result calculation not possible at present";
		try {
			res = manageTestsPages
					.finalizeStudentAnswers(testData);
			
			

		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (NamingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		request.getSession().setAttribute("message",
				"Test Completed. Thank you for attending." + res);
		response.sendRedirect("Student.jsp");
	}

}
